<?php

/**
 * HÃ nh trÃ¬nh khá»Ÿi nghiá»‡p functions and definitions
 *
 * Set up the theme and provides some helper functions, which are used in the
 * theme as custom template tags. Others are attached to action and filter
 * hooks in WordPress to change core functionality.
 *
 * When using a child theme you can override certain functions (those wrapped
 * in a function_exists() call) by defining them first in your child theme's
 * functions.php file. The child theme's functions.php file is included before
 * the parent theme's file, so the child theme functions would be used.
 *
 * @link http://codex.wordpress.org/Theme_Development
 * @link http://codex.wordpress.org/Child_Themes
 *
 * Functions that are not pluggable (not wrapped in function_exists()) are
 * instead attached to a filter or action hook.
 *
 * For more information on hooks, actions, and filters,
 * @link http://codex.wordpress.org/Plugin_API
 *
 * @package WordPress
 * @subpackage Twenty_Fourteen
 * @since HÃ nh trÃ¬nh khá»Ÿi nghiá»‡p 1.0
 */
/**
 * Set up the content width value based on the theme's design.
 *
 * @see hanhtrinhkhoinghiep_content_width()
 *
 * @since HÃ nh trÃ¬nh khá»Ÿi nghiá»‡p 1.0
 */
if (!isset($content_width)) {
    $content_width = 474;
}

/**
 * HÃ nh trÃ¬nh khá»Ÿi nghiá»‡p only works in WordPress 3.6 or later.
 */
if (version_compare($GLOBALS['wp_version'], '3.6', '<')) {
    require get_template_directory() . '/inc/back-compat.php';
}

if (!function_exists('hanhtrinhkhoinghiep_setup')) :

    /**
     * HÃ nh trÃ¬nh khá»Ÿi nghiá»‡p setup.
     *
     * Set up theme defaults and registers support for various WordPress features.
     *
     * Note that this function is hooked into the after_setup_theme hook, which
     * runs before the init hook. The init hook is too late for some features, such
     * as indicating support post thumbnails.
     *
     * @since HÃ nh trÃ¬nh khá»Ÿi nghiá»‡p 1.0
     */
    function hanhtrinhkhoinghiep_setup() {

        /*
         * Make HÃ nh trÃ¬nh khá»Ÿi nghiá»‡p available for translation.
         *
         * Translations can be added to the /languages/ directory.
         * If you're building a theme based on HÃ nh trÃ¬nh khá»Ÿi nghiá»‡p, use a find and
         * replace to change 'hanhtrinhkhoinghiep' to the name of your theme in all
         * template files.
         */
        load_theme_textdomain('hanhtrinhkhoinghiep', get_template_directory() . '/languages');


        // Add RSS feed links to <head> for posts and comments.
        add_theme_support('automatic-feed-links');

        // Enable support for Post Thumbnails, and declare two sizes.
        add_theme_support('post-thumbnails');

        // This theme uses wp_nav_menu() in two locations.
        register_nav_menus(array(
            'primary' => __('Top primary menu', 'hanhtrinhkhoinghiep'),
            'secondary' => __('Secondary menu in left sidebar', 'hanhtrinhkhoinghiep'),
        ));

        /*
         * Switch default core markup for search form, comment form, and comments
         * to output valid HTML5.
         */
        add_theme_support('html5', array(
            'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
        ));

        /*
         * Enable support for Post Formats.
         * See http://codex.wordpress.org/Post_Formats
         */
        add_theme_support('post-formats', array(
            'aside'
        ));

        // This theme allows users to set a custom background.
        add_theme_support('custom-background', apply_filters('hanhtrinhkhoinghiep_custom_background_args', array(
            'default-color' => 'f5f5f5',
        )));

        // Add support for featured content.
        add_theme_support('featured-content', array(
            'featured_content_filter' => 'hanhtrinhkhoinghiep_get_featured_posts',
            'max_posts' => 6,
        ));

        // This theme uses its own gallery styles.
        add_filter('use_default_gallery_style', '__return_false');
    }

endif; // hanhtrinhkhoinghiep_setup
add_action('after_setup_theme', 'hanhtrinhkhoinghiep_setup');

/**
 * Adjust content_width value for image attachment template.
 *
 * @since HÃ nh trÃ¬nh khá»Ÿi nghiá»‡p 1.0
 */
function hanhtrinhkhoinghiep_content_width() {
    if (is_attachment() && wp_attachment_is_image()) {
        $GLOBALS['content_width'] = 810;
    }
}

add_action('template_redirect', 'hanhtrinhkhoinghiep_content_width');

/**
 * Getter function for Featured Content Plugin.
 *
 * @since HÃ nh trÃ¬nh khá»Ÿi nghiá»‡p 1.0
 *
 * @return array An array of WP_Post objects.
 */
function hanhtrinhkhoinghiep_get_featured_posts() {
    /**
     * Filter the featured posts to return in HÃ nh trÃ¬nh khá»Ÿi nghiá»‡p.
     *
     * @since HÃ nh trÃ¬nh khá»Ÿi nghiá»‡p 1.0
     *
     * @param array|bool $posts Array of featured posts, otherwise false.
     */
    return apply_filters('hanhtrinhkhoinghiep_get_featured_posts', array());
}

/**
 * A helper conditional function that returns a boolean value.
 *
 * @since HÃ nh trÃ¬nh khá»Ÿi nghiá»‡p 1.0
 *
 * @return bool Whether there are featured posts.
 */
function hanhtrinhkhoinghiep_has_featured_posts() {
    return !is_paged() && (bool) hanhtrinhkhoinghiep_get_featured_posts();
}

/**
 * Register three HÃ nh trÃ¬nh khá»Ÿi nghiá»‡p widget areas.
 *
 * @since HÃ nh trÃ¬nh khá»Ÿi nghiá»‡p 1.0
 */
function hanhtrinhkhoinghiep_widgets_init() {


    register_sidebar(array(
        'name' => __('Tin tức Sidebar', 'hanhtrinhkhoinghiep'),
        'id' => 'sidebar-news',
        'description' => __('Sidebar bên trái mục tin tức.', 'hanhtrinhkhoinghiep'),
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h1 class="widget-title">',
        'after_title' => '</h1>',
    ));

    register_sidebar(array(
        'name' => __('Footer widget', 'hanhtrinhkhoinghiep'),
        'id' => 'sidebar-footer',
        'description' => __('NỘi dung chân trang', 'hanhtrinhkhoinghiep'),
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h1 class="widget-title">',
        'after_title' => '</h1>',
    ));
}

add_action('widgets_init', 'hanhtrinhkhoinghiep_widgets_init');

/**
 * Enqueue scripts and styles for the front end.
 *
 * @since HÃ nh trÃ¬nh khá»Ÿi nghiá»‡p 1.0
 */
function hanhtrinhkhoinghiep_scripts() {


    wp_enqueue_style('hanhtrinhkhoinghiep-style', get_stylesheet_uri());
//echo get_stylesheet_uri();
}

add_action('wp_enqueue_scripts', 'hanhtrinhkhoinghiep_scripts');
add_theme_support('menus');
add_theme_support('post-thumbnails');
if (function_exists('add_image_size')) {
    add_image_size('video', 238, 179, true);
}

// Metabox
define('RWMB_URL', trailingslashit(get_template_directory_uri() . '/meta-box'));
define('RWMB_DIR', trailingslashit(get_template_directory() . '/meta-box'));
require_once RWMB_DIR . 'meta-box.php';
include get_template_directory() . '/config-meta-boxes.php';

//function sent mail
function sent_mail($to = '', $subject = 'Contact', $message = 'Hello work!', $headers = null, $attachments = null) {
    return wp_mail($to, $subject, $message, $headers, $attachments);
}

//sql injection 
function sql_injecttion($text) {
    return mysql_escape_string(addslashes($text));
}

//phân trang 

function page_nav($page, $maxpage) {
    if ($maxpage <= 1) {
        return;
    }
    $paged = $page;
    $max = $maxpage;

    /** 	Add current page to the array */
    if ($paged >= 1)
        $links[] = $paged;

    /** 	Add the pages around the current page to the array */
    if ($paged >= 3) {
        $links[] = $paged - 1;
        $links[] = $paged - 2;
    }

    if (( $paged + 2 ) <= $max) {
        $links[] = $paged + 2;
        $links[] = $paged + 1;
    }

    echo '<ul>' . "\n";

    /** 	Previous Post Link */
    if (get_previous_posts_link())
        printf('<li>%s</li>' . "\n", $_GET['trang'] - 1);

    /** 	Link to first page, plus ellipses if necessary */
    if (!in_array(1, $links)) {
        $class = 1 == $paged ? ' class="current"' : '';

        printf('<li%s><a href="%s">%s</a></li>' . "\n", $class, get_permalink(49) . '/?trang=1', '1');

        if (!in_array(2, $links))
            echo '<li>…</li>';
    }

    /** 	Link to current page, plus 2 pages in either direction if necessary */
    sort($links);
    foreach ((array) $links as $link) {
        $class = $paged == $link ? ' class="active"' : '';
        printf('<li%s><a href="%s">%s</a></li>' . "\n", $class, get_permalink(49) . '/?trang=' . $link, $link);
    }

    /** 	Link to last page, plus ellipses if necessary */
    if (!in_array($max, $links)) {
        if (!in_array($max - 1, $links))
            echo '<li>…</li>' . "\n";

        $class = $paged == $max ? ' class="active"' : '';
        printf('<li%s><a href="%s">%s</a></li>' . "\n", $class, get_permalink(49) . '/?trang=' . $max, $max);
    }

    /** 	Next Post Link */
    if (get_next_posts_link())
        printf('<li>%s</li>' . "\n", $_GET['trang'] + 1);

    echo '</ul>' . "\n";
}
